<!--生成视频/成片-->
<template>
  <ele-modal
    width="460px"
    :visible="visible"
    :append-to-body="true"
    :close-on-click-modal="true"
    custom-class="ele-dialog-form"
    title="生成视频"
    @update:visible="updateVisible"
  >
    <el-form ref="form" :model="form" label-width="102px">
      <el-form-item label="生成数量:" prop="name">
        <el-input
          oninput="value=value.replace(/[^0-9]/g,'')"
          clearable
          :maxlength="20"
          v-model.number="form.maximumCount"
          placeholder="请输入生成数量"
        />
        <div v-if="videoItem">温馨提示：最大可剪辑数量为{{maxNum || 0}}</div>
      </el-form-item>
    </el-form>
    <template v-slot:footer>
      <el-button @click="updateVisible(false)">取消</el-button>
      <el-button type="primary" :loading="loading" @click="save">
        保存
      </el-button>
    </template>
  </ele-modal>
</template>

<script>
  import {saveAanCheck, saveAndBuildDiy, saveImgBuild} from "@/api/creatCenter/authoringClips";
  import {submitDiyJob, submitImageJob, submitProjectJob} from "@/api/explosiveCode/releaseActivity";

  export default {
    name: "generate-pieces",
    props:{
      // 弹窗是否打开
      visible: Boolean,
    },
    data(){
      return{
        // 表单数据
        form: {},
        loading:false,
        videoItem:{},
        maxNum:0
      }
    },
    methods: {
      show(item){
        this.videoItem=item //最大可剪辑数量
        this.maxNum=Number(item.max)-Number(item.montageCount)
        this.maxNum=this.maxNum<0?0:this.maxNum
        console.log("进入生成视频show========",item)
      },
      // 保存视频剪辑数量
      save(){
        if(this.form.maximumCount>this.maxNum){
          this.$message.error('已超过最大可剪辑数量')
          return
        }
        Object.assign(this.form, {
          id: this.videoItem.id, // 剪辑工程主键ID
          username: this.$store.state.user.info.username
        })

        // 1脚本剪辑 * 2自定义剪辑 * 3图文剪辑
        // <!-- * 1脚本剪辑 =AI剪辑 * 2自定义剪辑=口播剪辑 * 3图文剪辑-->
        const saveApi = this.videoItem.type === 1 ? submitProjectJob : this.videoItem.type === 2 ? submitDiyJob : submitImageJob
        this.loading=true
        saveApi(this.form)
          .then((data) => {
            this.$emit('query');
            this.updateVisible(false)
          })
          .catch((e) => {
            this.loading=false
            this.$message.error(e);
          });
      },
      /* 更新 visible */
      updateVisible(value) {
        this.loading=false
        delete this.form.maximumCount
        this.$emit('update:visible', value);
      }
    },
  }
</script>

<style scoped>

</style>
